<?php use_helper('Date') ?>
<?php use_helper('LetsManager') ?>

<?php if($sf_user->hasFlash('notice')): ?>
  <p class="notice"><?php echo $sf_user->getFlash('notice') ?></p>
<?php endif ?>


<h2>Bonjour <?php echo $member->getName().' ('.$member->getUsername().')' ?></h2>
<?php if(count($nextEvents) > 0): ?>
  <b>Les prochains événements prévus sont :</b><br/>
  <ul>
  <?php foreach($nextEvents as $event): ?>
    <li>&bull; <?php echo format_date($event->getDateBegin()). ': ' . 
      link_to($event->getName(),'@event_show?id='. $event->getId(),array('popup'=>true)) ?>
    </li>
  <?php endforeach ?>
  </ul>
  <br/>
<?php endif ?>

<b>Bienvenue aux derniers inscrits :</b>
<?php 
foreach($newestMembers as $member)
{
   echo lets_format_member($member).', ' ;
} ?>

<br/><br/>
<?php echo lets_member_money_sentence($current_user_id) ?><br/>
<?php if(count($exchangesPending) > 0): ?>
  <h2>Echanges à valider</h2>
  
  <table style="width: 95%" class="datalist">
    <thead>
      <tr>
        <th width="20%">Partenaire</th>
        <th width="15%">Catégorie</th>
        <th width="40%">Service</th>
        <th>Montant</th>
        <th>Actions</th>
      </tr>
    </thead>
    <tbody>
    <?php foreach ($exchangesPending as $exchange): ?>
      <tr>
        <td><?php echo lets_format_member($exchange->getPartnerMember($current_user_id),true) ?></td>
        <td><?php echo $exchange->getCategory()->getName() ?></td>
        <td><?php echo $exchange->getName() ?></td>
        <td><?php echo $exchange->getAmountWithSign($current_user_id) ?></td>
       
        <td><?php echo link_to('Accepter','@lets_exchange_validate_one?state='.LetsExchangeTable::STATE_ACCEPTED  .'&id=' . $exchange->getId()) ?>
        <?php echo link_to('Refuser', '@lets_exchange_validate_one?state='.LetsExchangeTable::STATE_REFUSED  .'&id=' . $exchange->getId()) ?>
        </td>
      </tr>
      <?php endforeach ?>
      <?php if(!$hasExchangesPending): ?>
      <tr>
        <td colspan="6">Aucun échange en attente</td>
      </tr>
      <?php endif ?>
    </tbody>
  </table>
  <?php if($hasExchangesPending): ?>
    <?php echo link_to('Tout accepter', '@lets_exchange_validate_many?state='.LetsExchangeTable::STATE_ACCEPTED) ?>
  <?php endif ?>
<?php else: ?>
  <b>Vous n'avez pas d'échange à valider pour l'instant.</b>
<?php endif ?>

<h2>Les 10 demandes se finissant bientôt</h2>
<table style="width: 95%" class="datalist">
  <thead>
    <tr>
      <th width="25%">Adhérent</th>
      <th width="10%">Catégorie</th>
      <th>Demande</th>
      <th width="10%">Expire</th>
    </tr>
  </thead>
  <tbody>
  <?php foreach ($asksExpire as $ask): ?>
    <tr>
      <td><?php echo lets_format_member($ask->getUser()) ?></td>
      <td><?php echo $ask->getCategory()->getName() ?></td>
      <td><?php echo $ask->getName() ?></td>
      <td><?php /*if($ask->isNeverExpire()): ?> Dans 1 an <?php else: ?> <?php*/ echo format_date($ask->getDateExpiration())  ?>
      <?php //endif ?></td>
    </tr>
    <?php endforeach ?>
    <?php if(count($asksExpire) == 0): ?>
    <tr>
      <td colspan="4">Aucune demande pour l'instant</td>
    </tr>
    <?php endif ?>
  </tbody>
</table>

<h2>Les 10 dernières offres ajoutées</h2>
<table style="width: 95%" class="datalist">
  <thead>
    <tr>
      <th width="25%">Adhérent</th>
      <th width="10%">Catégorie</th>
      <th>Offre</th>
      <th width="10%">Création</th>
    </tr>
  </thead>
  <tbody>
  <?php foreach ($offersNewest as $offer): ?>
    <tr>
      <td><?php echo lets_format_member($offer->getUser(),true) ?></td>
      <td><?php echo $offer->getCategory()->getName() ?></td>
      <td><?php echo $offer->getName() ?></td>
      <td><?php echo format_date($offer->getCreatedAt())?></td>
    </tr>
    <?php endforeach ?>
    <?php if(count($offersNewest) == 0): ?>
    <tr>
      <td colspan="4">Aucune offre pour l'instant</td>
    </tr>
    <?php endif ?>
  </tbody>
</table>

<br />
